﻿using System;
using System.Collections.Generic;
using WindowsGame.Data;
using WindowsGame.Enums;
using WindowsGame.Library.Data;

namespace WindowsGame.Manager
{
	public interface IDataManager
	{
		AllData LoadData(String[] files);
	}

	public class DataManager : IDataManager
	{
		private readonly IFileManager fileManager;

		public DataManager(IFileManager fileManager)
		{
			this.fileManager = fileManager;
		}

		public AllData LoadData(String[] files)
		{
			// Load board data.
			String boardFile = files[0];
			IList<String> lines = fileManager.LoadTxt(boardFile);
			String line = lines[0];
			GameSize gameSize = (GameSize)Enum.Parse(typeof(GameSize), line, true);

			// Load snake data.
			String snakeFile = files[1];
			SnakeData[] snakeData = fileManager.LoadXml<SnakeData[]>(snakeFile);
			return new AllData(gameSize, snakeData);
		}
	}
}